# x265
# Builds from https://github.com/puppylinux-woof-CE/petbuilds
# File auto generated by ./mk_petbuild.sh. Edit as necessary.

. ../func
. ../build.conf

URL=https://bitbucket.org/multicoreware/x265/downloads
PKG=x265
VER=2.4
COMP=tar.gz
DESC="HVEC encoder"
DEPS=
CAT=BuildingBlock
DESKTOP=x265.desktop
BUILD=
CWD=$(pwd)
[ -z "$MWD" ] && MWD=$(dirname $CWD)
[ -z "$BUILD" ] && BUILD=$DEF_BUILD
# comment these 2 below if you use a custom package() function
[ -f "$DESKTOP" ] || DESKTOP=not
[ -z "$DEPS" ] && DEPS=not

ARCH=$(uname -m)
case $ARCH in # set in build.conf
 *64) 	LIBDIR=$LIBCONF64 
		FLAGS=$CF64;;
 arm*)	LIBDIR=$LIBCONFarm
		FLAGS="-O2" ;;
 i686) 	LIBDIR=$LIBCONF32 
		FLAGS=$CF32;;
	*) 	LIBDIR=$LIBCONF32 
		FLAGS="-O2 -march=$ARCH -mtune=$ARCH";;
esac

move() {
	mv -f ${PKG}_${VER} ${PKG}-${VER}
}

build_() {
	(
	cd ${PKG}-${VER}
		(
		cd build
		cmake -DCMAKE_INSTALL_PREFIX=/usr \
				-DCMAKE_BUILD_TYPE=release \
				-DBUILD_SHARED_LIBS=true ../source || exit
		make || exit
		make DESTDIR=${CWD}/${PKG}-install install
		)
	)
	# need a hack
	if [ "$LIBDIR" = 'lib64' ];then
		mv -f ${PKG}-install/usr/lib ${PKG}-install/usr/lib64
		sed -i "s%lib$%lib64%g" ${PKG}-install/usr/lib64/pkgconfig/*
	fi
}

# main
retrieve ${PKG}_${VER}.${COMP}
extract ${PKG}_${VER}.${COMP}
move
build_
package_std $PKG $VER $ARCH $DESKTOP "$DESC" $DEPS $CAT
